﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2009
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
*/

using System;
using MbUnit.Framework;
using WatiN.Core;
using DotNetNuke.Tests.UI.WatiN.Common;
using Gallio.Framework;
using DotNetNuke.Tests.UI.WatiN.Utilities;
using System.Configuration;
using WatiN.Core.DialogHandlers;
using DotNetNuke.Tests.UI.WatiN.Common.WatiNObjects;
using System.IO;
using System.Reflection;




namespace DotNetNuke.Tests.UI.WatiN.HTMLTests
{
    [TestFixture]

    public class HTMLModuleTests : HTMLBase
    {
        #region Test Setup and TearDown

        [SetUp]
        public void SetUp()
        {

            SetUpTest();
        }

        [TearDown]
        public void TearDown()
        {
            TearDownTest();
        }

        #endregion

        #region Tests

        [Test]
        public void Direct_Publish_Add_New_Module()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName,"None Specified");
            System.Threading.Thread.Sleep(4000);

            //Act
            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Direct Publish");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Assert
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            homePage.ViewRadioButton.Checked = true;
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            homePage.EditRadioButton.Checked = true;
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("Hover here, then click toolbar to edit content"));
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Direct_Publish_Edit_Content_Edit_Page()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This is module Content";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Direct Publish");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Act
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.SelectTextEditorStyleByName(ieInstance, "BASIC");
            htmlModule.ModuleTextBox.Value = moduleContent;
            htmlModule.SaveContentLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Assert
            homePage.ViewRadioButton.Checked = true;
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            homePage.EditRadioButton.Checked = true;
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleName));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Direct_Publish_Preview_Current_Content()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This text is <strong>BOLD</strong>";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Direct Publish");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Add Content to the module
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.SelectTextEditorStyleByName(ieInstance, "BASIC");
            htmlModule.ModuleTextBox.Value = moduleContent;
            htmlModule.SaveContentLink.Click();
            System.Threading.Thread.Sleep(2000);

            //Act 
            htmlModule.GetEditModuleContentLink(0).Click();
            System.Threading.Thread.Sleep(1000);
            htmlModule.PreviewContentLink.Click();

            //Assert
            Assert.IsTrue(htmlModule.PreviewTable.Exists);
            Assert.AreEqual("This text is BOLD", htmlModule.PreviewSpan.Text);
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Direct_Publish_Preview_From_Version_History()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This text is the first version of content";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Direct Publish");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.ManageWorkFlowsLink.Click();
            htmlModule.VersionHistorySettingsExpandButton.Click();
            htmlModule.VersionHistoryTextField.Value = "5";
            htmlModule.SaveVersionHistoryLink.Click();

            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);
            moduleContent = "This text is the second version of content";
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);

            //Act 
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            htmlModule.GetVersionPreviewButtonByNumber(1).Click();

            //Assert 
            Assert.AreEqual("This text is the first version of content", htmlModule.PreviewSpan.Text);
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Direct_Publish_Rollback_To_Previous_Version()
        {
             //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This text is the first version of content";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Direct Publish");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.ManageWorkFlowsLink.Click();
            htmlModule.VersionHistorySettingsExpandButton.Click();
            htmlModule.VersionHistoryTextField.Value = "5";
            htmlModule.SaveVersionHistoryLink.Click();

            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);
            moduleContent = "This text is the second version of content";
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("This text is the second version of content"));

            //Act 
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            htmlModule.GetVersionRollbackButtonByNumber(1).Click();

            //Assert 
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("This text is the first version of content"));
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Edit_Version_History_Settings()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This text is the first version of content";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Direct Publish");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.ManageWorkFlowsLink.ClickNoWait();
            System.Threading.Thread.Sleep(1000);
            htmlModule.VersionHistorySettingsExpandButton.Click();
            htmlModule.VersionHistoryTextField.Value = "5";
            htmlModule.SaveVersionHistoryLink.Click();

            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);
            moduleContent = "This text is the second version of content";
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);
            moduleContent = "This text is the third version of content";
            htmlModule.AddContentToModule(moduleContent, 0);
            System.Threading.Thread.Sleep(1000);

            //Act 
             htmlModule.GetModuleSettingsImage(0).Click();
             htmlModule.ManageWorkFlowsLink.ClickNoWait();
             System.Threading.Thread.Sleep(1000);
            htmlModule.VersionHistorySettingsExpandButton.Click();
            htmlModule.VersionHistoryTextField.Value = "1";
            htmlModule.SaveVersionHistoryLink.Click();

            //Assert 
            ieInstance.GoTo(SiteURL + "/testpage.aspx");
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            Assert.IsTrue(htmlModule.VersionTable.TableRows.Count == 4);

            htmlModule.SaveContentLink.Click();
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            Assert.IsTrue(htmlModule.VersionTable.TableRows.Count == 2);
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Content_Staging_Edit_From_Edit_Content_Page_Draft()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This text is the first version of content";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            //Add Content to the module
            htmlModule.AddContentToModule(moduleContent, 0);
            //Select Content staging
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Content Staging");
            htmlModule.UpdateLink.Click();
            
            //Act
            System.Threading.Thread.Sleep(1000);
            moduleContent = "This content will be a draft version";
            htmlModule.AddContentToModule(moduleContent, 0);
            
            //Assert
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            homePage.ViewRadioButton.Checked = true;
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("This text is the first version of content"));
            homePage.EditRadioButton.Checked = true;
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            Assert.IsTrue(htmlModule.GetStateCellByNumber(2).InnerHtml.Contains("Draft"));
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Content_Staging_Edit_From_Edit_Content_Page_Publish()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            //Select Content staging
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Content Staging");
            htmlModule.UpdateLink.Click();

            //Act
            System.Threading.Thread.Sleep(1000);
            String moduleContent = "This content will be published";
            htmlModule.AddContentToModulePublishModule(moduleContent, 0);
            

            //Assert
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            homePage.ViewRadioButton.Checked = true;
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            homePage.EditRadioButton.Checked = true;
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            Assert.IsTrue(htmlModule.GetStateCellByNumber(1).InnerHtml.Contains("Published"));
        }

        [Test]
        [DependsOn("Direct_Publish_Add_New_Module")]
        public void Content_Staging_Rollback_To_Previous_Version()
        {
            //Arrange
            WatiNBase homePage = new WatiNBase(ieInstance, SiteURL, DatabaseName);
            LoginPage loginPage = new LoginPage(homePage);
            loginPage.LoginUser(TestUsers.Admin.UserName, TestUsers.Admin.Password);
            ControlPanel controlPanel = null;
            RibbonBar ribbonBar = null;
            bool usesRibbonBar = false;

            //Add A Page for testing
            PageSettingsPage newPage = new PageSettingsPage(homePage);
            String pageName = "Test Page";
            String moduleName = "Test Module";
            String moduleContent = "This text is the first version of content";
            if (homePage.ControlPanelElement.Id.Contains(homePage.RibbonBarID))
            {
                ribbonBar = new RibbonBar(homePage);
                ribbonBar.NewPageLink.Click();
                usesRibbonBar = true;
            }
            else
            {
                controlPanel = new ControlPanel(homePage);
                controlPanel.AddPageLink.Click();
            }
            newPage.AddPageSelectTemplate(pageName, "None Specified");
            System.Threading.Thread.Sleep(4000);

            if (!usesRibbonBar)
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML");
                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    controlPanel.AddModuleToPage(moduleName, "HTML Pro");
                }
            }
            else
            {
                if (VersionType.CompareTo("Community") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML");

                }
                else if (VersionType.CompareTo("Professional") == 0 || VersionType.CompareTo("Enterprise") == 0)
                {
                    ribbonBar.AddHTMLModuleToPage(moduleName, "HTML Pro");

                }
            }
            HTMLModule htmlModule = new HTMLModule(homePage);
            System.Threading.Thread.Sleep(2000);
            //Add Content to the module
            htmlModule.AddContentToModule(moduleContent, 0);
            //Select Content staging
            htmlModule.GetModuleSettingsImage(0).Click();
            htmlModule.WorkflowSelectList.Select("Content Staging");
            htmlModule.UpdateLink.Click();
            System.Threading.Thread.Sleep(1000);

            //Add more content
            moduleContent = "This text is the second version of content";
            htmlModule.AddContentToModulePublishModule(moduleContent, 0);
            moduleContent = "This text is the third version of content";
            htmlModule.AddContentToModule(moduleContent, 0);

            //Act
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            htmlModule.GetVersionRollbackButtonByNumber(1).Click();
            
            //Assert
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("This text is the first version of content"));
            homePage.ViewRadioButton.Checked = true;
            Assert.IsFalse(homePage.ContentDiv.InnerHtml.Contains(moduleContent));
            Assert.IsTrue(homePage.ContentDiv.InnerHtml.Contains("This text is the second version of content"));
            homePage.EditRadioButton.Checked = true;
            htmlModule.GetEditModuleContentLink(0).Click();
            htmlModule.VersionHistoryTableExpandButton.Click();
            System.Threading.Thread.Sleep(5000);
            Assert.IsTrue(htmlModule.GetStateCellByNumber(1).InnerHtml.Contains("Draft"));
        }


        #endregion
    }
}
